<?php

	// TITLE: Project_expense AUTO MODEL
	// FILE: scaffolding/model/project_expense.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createProjectExpense = function($con, $projectExpense) {
		$sql = 'INSERT INTO project_expense (id, project_id, title, description, amount, when_entered, who_entered, when_authorized, who_authorized, type_id) VALUES (';
		$sql .= $project_expense->getId() . ', ';
		$sql .= $project_expense->getProjectId() . ', ';
		$sql .= $project_expense->getTitle() . ', ';
		$sql .= $project_expense->getDescription() . ', ';
		$sql .= $project_expense->getAmount() . ', ';
		$sql .= $project_expense->getWhenEntered() . ', ';
		$sql .= $project_expense->getWhoEntered() . ', ';
		$sql .= $project_expense->getWhenAuthorized() . ', ';
		$sql .= $project_expense->getWhoAuthorized() . ', ';
		$sql .= $project_expense->getTypeId() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readProjectExpense = function($con, $id) {
		$sql = 'SELECT * FROM project_expense WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$projectExpense = new ProjectExpense();
			$projectExpense->setId(result[0]);
			$projectExpense->setProjectId($dbio->select($readProject(result[1])));
			$projectExpense->setTitle(result[2]);
			$projectExpense->setDescription(result[3]);
			$projectExpense->setAmount(result[4]);
			$projectExpense->setWhenEntered(result[5]);
			$projectExpense->setWhoEntered(result[6]);
			$projectExpense->setWhenAuthorized(result[7]);
			$projectExpense->setWhoAuthorized(result[8]);
			$projectExpense->setTypeId($dbio->select($readType(result[9])));
		} else {
			$projectExpense = false;
		}
		return $projectExpense;
	};

	$updateProjectExpense = function($con, $projectExpense) {
		$sql = 'UPDATE project_expense SET ';
		$sql .= 'id = ' . $project_expense->getId() . ', ';
		$sql .= 'project_id = ' . $project_expense->getProjectId() . ', ';
		$sql .= 'title = ' . $project_expense->getTitle() . ', ';
		$sql .= 'description = ' . $project_expense->getDescription() . ', ';
		$sql .= 'amount = ' . $project_expense->getAmount() . ', ';
		$sql .= 'when_entered = ' . $project_expense->getWhenEntered() . ', ';
		$sql .= 'who_entered = ' . $project_expense->getWhoEntered() . ', ';
		$sql .= 'when_authorized = ' . $project_expense->getWhenAuthorized() . ', ';
		$sql .= 'who_authorized = ' . $project_expense->getWhoAuthorized() . ', ';
		$sql .= 'type_id = ' . $project_expense->getTypeId() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteProjectExpense = function($con, $id) {
		$sql = 'DELETE FROM project_expense WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listProjectExpense = function($con) {
		$sql = 'SELECT * FROM project_expense';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$projectExpenses = array();
			while ($result = mysqli_fetch_array($results)) {
				$projectExpense = new ProjectExpense();
				$projectExpense->setId(result[0]);
				$projectExpense->setProjectId($dbio->select($readProject(result[1])));
				$projectExpense->setTitle(result[2]);
				$projectExpense->setDescription(result[3]);
				$projectExpense->setAmount(result[4]);
				$projectExpense->setWhenEntered(result[5]);
				$projectExpense->setWhoEntered(result[6]);
				$projectExpense->setWhenAuthorized(result[7]);
				$projectExpense->setWhoAuthorized(result[8]);
				$projectExpense->setTypeId($dbio->select($readType(result[9])));
				$projectExpenses[] = projectExpense;
			}// end while
		} else {
			$projectExpenses = false;
		}
		return $projectExpenses;
	};

